<?php

namespace App\JsonRpc\ServiceProvider;

use App\Constants\ErrorCode;
use App\Utils\ApiUtils;
use App\Utils\ServerUtil;
use Hyperf\RpcServer\Annotation\RpcService;
use Hyperf\Utils\ApplicationContext;

/**
 * 注意，如希望通过服务中心来管理服务
 * @RpcService(name="WxuserService", protocol="jsonrpc", server="jsonrpc")
 */
class WxuserService implements WxuserServiceInterface
{
    /**
     * 通过openids获取用户信息
     * @Author abell
     * @DateTime 2020-05-28
     * @param array $request
     * @return string
     */
    public function getUserInfo(string $data): string
    {
        $data = json_decode($data,true);
        if(! array_key_exists('selects',$data)) $data['selects'] = 'openid,nickname,add_time';
        ServerUtil::info('rpc-WxuserService 查询用户信息 - 进入',['path'=>'WxuserService','parameter'=>$data]);
        $obj = ApplicationContext::getContainer()->get(\App\Service\WxuserService::class);
        $result = $obj->getUserInfoByOpenids($data['openids'],$data['selects']);
        $response_data = json_encode(ApiUtils::send($result['code'],$result['msg'],$result['data'],1));
        ServerUtil::info('rpc-WxuserService 查询用户信息 - 退出',['path'=>'WxuserService','parameter'=>$data]);
        return  $response_data;
    }
}


